window.$config = {
    host: function () {
        var base = '/index.php?s=';
        if (location.hostname == 'h5.oeeee.com') {
            return 'http://h5.oeeee.com' + base;
        } else if (location.hostname == 'h5.test.yixiaoqun.com') {
            return 'http://test.yixiaoqun.com' + base;
        } else {
            return base;
        }
    },
    rex: {mobile: /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/},
    getCookie: function (name) {
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

        if(arr=document.cookie.match(reg))

            return decodeURI(arr[2]);
        else
            return null;
    },
    setCookie: function (c_name, value, expiredays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + value + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ';path=/';
    },
    GetQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return unescape(r[2]);
        return null;
    },
    dataURLtoBlob: function (base64Data) {
        var byteString;
        if (base64Data.split(',')[0].indexOf('base64') >= 0)
            byteString = atob(base64Data.split(',')[1]);
        else
            byteString = unescape(base64Data.split(',')[1]);
        var mimeString = base64Data.split(',')[0].split(':')[1].split(';')[0];
        var ia = new Uint8Array(byteString.length);
        for (var i = 0; i < byteString.length; i++) {
            ia[i] = byteString.charCodeAt(i);
        }
        return new Blob([ia], {type: mimeString});
    },
    audioAutoPlay: function () {
        var audio = document.getElementById('bgmusic');
        audio.play();
        document.addEventListener("WeixinJSBridgeReady", function () {
            audio.play();
        }, false);
        document.addEventListener('YixinJSBridgeReady', function () {
            audio.play();
        }, false);
        $('.music').click(function () {
            if (audio !== null) {
                if (audio.paused) {
                    audio.play();
                    $('.music').addClass('on');
                } else {
                    audio.pause();
                    $('.music').removeClass('on');
                }
            }
        });
    },
    toScrollElement: function (ele) {
        if (ele) {
            setTimeout(function () {
                var offTop = document.querySelector(ele).offsetTop;
                document.documentElement.scrollTop = document.body.scrollTop = offTop;
            }, 100);
        }
    },
    IsPC: function () {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    },
    iswx: function () {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        }
    },
    wxConfig: function (config) {
        wx.config({
            debug: false,
            appId: config.appId,
            timestamp: config.timestamp,
            nonceStr: config.nonceStr,
            signature: config.signature,
            jsApiList: ['chooseImage', 'uploadImage', 'previewImage', 'onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareWeibo']
        });
    },
    wxShare: function (Option) {
        if (!this.iswx())
            return;
        var num = 0,
            _this = this,
            time = setInterval(function () {
                if (num > 100) {
                    clearTimeout(time);
                }
                try {
                    if (!wx || !oe_wxconfig) {
                    }
                    ;
                } catch (e) {
                    num++;
                    return;
                }
                clearTimeout(time);
                _this.wxConfig(oe_wxconfig);
                if (!Option)
                    Option = {};
                var title = Option.title ? Option.title : "一小群",
                    summary = Option.cont ? Option.cont : "一小群，优质的社群营销工具",
                    link = Option.url ? Option.url : location.href,
                    thumb = Option.logo ? Option.logo : 'http://' + location.hostname + '/logo.jpg',
                    content = {
                        title: title,
                        desc: summary,
                        link: link,
                        imgUrl: thumb,
                        success: function () {
                            if (Option.success) {
                                Option.success();
                            }
                        },
                        cancel: function () {
                        }
                    };
                wx.ready(function () {
                    wx.onMenuShareTimeline(content);
                    wx.onMenuShareAppMessage(content);
                    wx.onMenuShareQQ(content);
                    wx.onMenuShareWeibo(content);
                });
            }, 100);
    },
    wxVerify: function (value) {
        if (!this.getCookie('yxq_wx_token') || this.getCookie('yxq_wx_token') == 'abc1024' && (location.hostname == 'h5.test.yixiaoqun.com' || location.hostname == 'h5.yixiaoqun.com')) {
            var href = encodeURIComponent(location.href.split('?')[0] + '?aid=' + $config.GetQueryString('aid') + (value ? value : '')),
                tourl = this.url + '&h52go=' + href;
            location.href = tourl;
            return false;
        } else {
            if (document.body.style.display = 'none') {
                document.body.style.display = 'block';
            }
            return true;
        }
    },
    init: function () {
        /*if ((location.hostname == '192.168.10.108' || location.hostname == 'localhost') && !this.getCookie('wx_btjt_wxname')) {
            this.setCookie('yxq_wx_token', '9fb6IKRV8%2BrdJZhKCuRwWNRbT%2BoQ8fHEQ%2FcLQAeb%2BStPF5O1Y6RqeMUFV9wCpc9UDo4dYIwRfymsyCLDeCBxHpX8PpUuuak607xTplpn3nitHENjPQNtCHLk1HApExg4jXzVAoBPrx%2Blsumt');
        }*/
        if (!this.iswx())
            return;
        var jwx1 = document.createElement('script');
        jwx1.setAttribute('src', 'http://res.wx.qq.com/open/js/jweixin-1.2.0.js');
        document.body.appendChild(jwx1);
        var jwx2 = document.createElement('script');
        jwx2.setAttribute('src', 'https://m.mp.oeeee.com/helper.php?m=WxHelper&a=config&domain=oeeee.com');
        document.body.appendChild(jwx2);
    }
};
$config.init();
$config.wxShare({
    title : '全民守护生命线',
    cont : '平安交通百分百知识竞赛等你来挑战！',
    url : 'http://h5.oeeee.com/h5/v18/btjt',
    logo : 'http://h5.oeeee.com/h5/v18/btjt/logo.jpg'
})
if (typeof Vue == 'function') {
    Vue.http.options.emulateJSON = true;
    Vue.http.interceptors.push(function (request, next) {
        request.credentials = true;
        next();
    });
    Vue.mixin({
        created: function () {
            if (document.body.style.display = 'none') {
                document.body.style.display = 'block';
            }
        },
        methods: {
            common: function () {
                return {
                    httplock: true,
                    converBr: function (value) {
                        var str = value.replace(/\r\n/g, '<br>');
                        str = str.replace(/[\r,\n]/g, '<br>');
                        return str;
                    },
                    http: function (_this, config) {
                        var $__2 = this;
                        if (config.lock) {
                            if (!this.httplock)
                                return;
                            this.httplock = false;
                        }
                        ;
                        var successCallback = function (res) {
                                var json = res.body;
                                if (json.status == 1 || config.allow) {
                                    if (config.success)
                                        config.success.call(_this, json);
                                } else {
                                    /*swal({
                                        title: json.msg,
                                        type: "warning"
                                    });*/
                                    if (config.error)
                                        config.error.call(_this, json);
                                }
                                if (config.loading) {
                                    setTimeout(function () {
                                        _this.load.loading = false;
                                    }, 250);
                                }
                                if (config.after)
                                    config.after.call(_this, json);
                                if (config.lock) {
                                    setTimeout(function () {
                                        $__2.httplock = true;
                                    }, config.locktime ? config.locktime : 0);
                                }
                            },
                            errorCallback = function (res) {
                                var json = res.body;
                                if (config.lock) {
                                    setTimeout(function () {
                                        $__2.httplock = true;
                                    }, config.locktime ? config.locktime : 0);
                                }
                            };
                        config.type = config.type || 'post';
                        if (config.type == 'post') {
                            var options = config.options ? config.options : null;
                            _this.$http[config.type]($config.host() + config.url, config.body, options).then(successCallback, errorCallback);
                        } else {
                            _this.$http[config.type]($config.host() + config.url, config.body).then(successCallback, errorCallback);
                        }
                    }
                };
            }
        }
    });
}
